/*
 * 版权所有(C)，上海海鼎信息工程股份有限公司，lizhixing，所有权利保留。
 * <p>
 * 项目名：	boot-demo
 * 文件名：	SendMailServiceImpl
 * 模块说明：
 * 修改历史：
 * 2022/3/2 - lizhixing - 创建。
 */
package com.lovely602.boot.bootdemo.service.impl;

import com.lovely602.boot.bootdemo.config.MailConfiguration;
import com.lovely602.boot.bootdemo.service.SendMailService;
import com.lovely602.boot.bootdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * 
 * 发送邮件业务
 * 
 * @author lizhixing
 */
@Service
public class SendMailServiceImpl implements SendMailService {

  @Autowired
  private JavaMailSender mailSender;
  @Autowired
  private MailConfiguration mailConfiguration;
  @Autowired
  private UserService userService;

  @Override
  public boolean sendMail() throws MessagingException {

    MimeMessage mimeMessage = mailSender.createMimeMessage();

    MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
    // 设置邮件发送方
    message.setFrom(mailConfiguration.getUsername());
    // 设置邮件主题
    message.setSubject("您有个快递正在派送中...");
    // 设置邮件接收方
    message.setTo("lizhixing@hd123.com");
    // 设置邮件内容
    message.setText("您收到了一封测试邮件,请忽略...");
    // 发送邮件
    mailSender.send(mimeMessage);

    return false;
  }
}
